<?php
require_once("admin_header.php");
require_once("../include/set_get_key.php");
$sql      = "SELECT max(`contest_id`) as upid, min(`contest_id`) as btid  FROM `cr_contest`";
$page_cnt = 50;
$result   = mysql_query($sql);
echo mysql_error();
$row  = mysql_fetch_object($result);
$base = intval($row->btid);
$cnt  = intval($row->upid) - $base;
$cnt  = intval($cnt / $page_cnt) + (($cnt % $page_cnt) > 0 ? 1 : 0);
if (isset($_GET['page']))
    $page = intval($_GET['page']);
else
    $page = $cnt;
$pstart = $base + $page_cnt * intval($page - 1);
$pend   = $pstart + $page_cnt;

$sql = "select `contest_id`,`contest_title`,`contest_0_start`,`contest_0_end`,`contest_1_start`,`contest_1_end`,`contest_0_active`,`contest_1_active`,`contest_active` FROM `cr_contest` where contest_id>=$pstart and contest_id <=$pend order by `contest_id` desc";

$result = mysql_query($sql) or die(mysql_error());

?>
<style type="text/css">
<!--
.STYLE1 {color: #FFFFFF}
.STYLE2 {font-size: 12px}
.green  {color: green}
.red    {color: red}
-->
</style>
      <div class="fr wid59">
        <h2 class="h2">比赛列表</h2>  
    <?php 
  	for ($i = 1; $i <= $cnt; $i++) 
	{
	    if ($i > 1)
	        echo '&nbsp;';
	    if ($i == $page)
	        echo "<span class=red>$i</span>";
	    else
	        echo "<a href='contest_list.php?page=" . $i . "'>" . $i . "</a>";
	}
  ?>
        <div class="middle">

  <table width="100%" border="0" cellpadding="0" cellspacing="1" bgcolor="#FFFFFF">
  <tr>
    <td nowrap height="30" align="center" bgcolor="#316fb5"><h4 class="STYLE3 STYLE1">赛事ID</h4></td>
    <td nowrap align="center" bgcolor="#316fb5"><h4 class="STYLE3 STYLE1">赛事标题</h4>
      <h4 class="STYLE3 STYLE1">（点击查看报名情况）</h4></td>
    <td nowrap align="center" bgcolor="#316fb5"><h4 class="STYLE3 STYLE1"><?php echo $sf_name; ?></h4>
      <h4 class="STYLE3 STYLE1">开始时间</h4></td>
    <td nowrap align="center" bgcolor="#316fb5"><h4 class="STYLE3 STYLE1">结束时间</h4></td>
    <td nowrap align="center" bgcolor="#316fb5"><h4 class="STYLE3 STYLE1"><?php echo $rj_name; ?></h4>
      <h4 class="STYLE3 STYLE1">开始时间</h4></td>
    <td nowrap align="center" bgcolor="#316fb5"><h4 class="STYLE3 STYLE1">结束时间</h4></td>
    <td nowrap align="center" bgcolor="#316fb5"><h4 class="STYLE3 STYLE1">操作</h4></td>
    </tr>
    <?php 
	for (; $row = mysql_fetch_object($result); ) 
	{
    ?>
  <tr>
    <td height="30" align="center" bgcolor="#D4DFFF"><span class="STYLE5 STYLE2"><a href='<?php echo "../contest.php?cid=$row->contest_id";?>'><?php echo $row->contest_id;?></a></span></td>
    <td align="center" bgcolor="#D4DFFF"><span class="STYLE5 STYLE2"><a href='<?php echo "../results.php?cid=$row->contest_id";?>'><?php echo $row->contest_title;?></a></span></td>
    <td align="center" bgcolor="#D4DFFF"><span class="STYLE5 STYLE2"><?php echo $row->contest_0_start;?></span></td>
    <td align="center" bgcolor="#D4DFFF"><span class="STYLE5 STYLE2"><?php echo $row->contest_0_end;?></span></td>
    <td align="center" bgcolor="#D4DFFF"><span class="STYLE5 STYLE2"><?php echo $row->contest_1_start;?></span></td>
    <td align="center" bgcolor="#D4DFFF"><span class="STYLE5 STYLE2"><?php echo $row->contest_1_end;?></span></td>
    <td nowrap align="center" bgcolor="#D4DFFF"><span class="STYLE5 STYLE2">
    <?php echo "<a href=contest_df_change.php?cid=$row->contest_id&getkey=" . $_SESSION['getkey'] . ">" . ($row->contest_active == "N" ? "<span class=green>改为显示</span>" : "<span class=red>改为隐藏</span>") . "</a>";?> | <?php echo "<a href=contest_edit.php?cid=$row->contest_id>编辑</a>";?></span></td>
    </tr>
    <?php 
	}
    ?>
</table>
        </div>
  </div>
     
<?php 

require_once("menu.php");

require_once("./admin_footer.php");
?>

